﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.Linq;
using System.Linq;
namespace Exact_Extension
{
    public partial class InvoiceDetail : DevExpress.XtraEditors.XtraForm
    {
        ExactDataContext DS;
        ISHCMC_InvoiceHeader InvoiceHeader;
        Common common;
        public InvoiceDetail(ExactDataContext _DS, ISHCMC_InvoiceHeader _InvoiceHeader)
        {
            InitializeComponent();
            DS = _DS;
            InvoiceHeader = _InvoiceHeader;
            this.Text = this.Text + " " + InvoiceHeader.StudentID.ToString();
            common = new Common(_DS);
        }
        private void LoadData()
        {

            var queryInv = from Invoice in DS.ISHCMC_Invoices
                           where Invoice.InvoiceHeaderID == InvoiceHeader.ID && Invoice.Status == 0 
                           select Invoice;
            this.iSHCMCInvoiceBindingSource.DataSource = queryInv;
        }

        private void InvoiceDetail_Load(object sender, EventArgs e)
        {

            this.LoadData();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            this.LoadData();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            
         

            ISHCMC_Invoice itemInv = (ISHCMC_Invoice)this.gridView_InvoiceDetail.GetRow(this.gridView_InvoiceDetail.GetSelectedRows()[0]);
            MsgDeleteInvoice msgDelInv = new MsgDeleteInvoice(itemInv, common);
            msgDelInv.StartPosition = FormStartPosition.CenterScreen;
            DialogResult result = msgDelInv.ShowDialog();
            if (result == DialogResult.OK)
            {
                this.LoadData();
            }
            if (result == DialogResult.No)
            {
                MessageBox.Show("Can not delete this invoice , please you check with administrator again !!");
            }
            this.LoadData();
        }
      
    }
}